{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import datasets\n",
    "\n",
    "digits = datasets.load_digits()\n",
    "X = digits.data\n",
    "y = digits.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.8, random_state=666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.93115438108484"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import LogisticRegression\n",
    "\n",
    "log_reg = LogisticRegression()\n",
    "log_reg.fit(X_train, y_train)\n",
    "log_reg.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_predict = log_reg.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import precision_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.93115438108484"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对于多分类问题, 要指定precision_score的参数\n",
    "precision_score(y_test, y_predict, average='micro')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[147,   0,   1,   0,   0,   1,   0,   0,   0,   0],\n",
       "       [  0, 123,   1,   2,   0,   0,   0,   3,   4,  10],\n",
       "       [  0,   0, 134,   1,   0,   0,   0,   0,   1,   0],\n",
       "       [  0,   0,   0, 138,   0,   5,   0,   1,   5,   0],\n",
       "       [  2,   5,   0,   0, 139,   0,   0,   3,   0,   1],\n",
       "       [  1,   3,   1,   0,   0, 146,   0,   0,   1,   0],\n",
       "       [  0,   2,   0,   0,   0,   1, 131,   0,   2,   0],\n",
       "       [  0,   0,   0,   1,   0,   0,   0, 132,   1,   2],\n",
       "       [  1,   9,   2,   3,   2,   4,   0,   0, 115,   4],\n",
       "       [  0,   1,   0,   5,   0,   3,   0,   2,   2, 134]], dtype=int64)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "\n",
    "confusion_matrix(y_test, y_predict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 可视化混淆矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAECCAYAAADesWqHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAACuVJREFUeJzt3U2IXfUZx/HfLzOjY2KHCBHETOgoFFsVSmQovkAWRqStUjddWFCom2xajSKIduOyGxFdFCHEuqnYRcyiSFEL6qILQycvoMlYEG3zqk4XcVQImZeni3uDL5nOPUPvc8/cPN8PCJnx5s+Tm/udc+7knP84IgSglg1tDwBg8AgfKIjwgYIIHyiI8IGCCB8oqLXwbf/U9j9tf2j7ybbmaMr2Nttv2561fdT27rZnasL2iO3Dtl9re5YmbG+2vc/2B93n+ra2Z+rF9mPd18T7tl+xPd72TL20Er7tEUl/kPQzSTdK+pXtG9uYZQ0WJT0eET+Sd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yLpP/0fYg8wzavxMyDsF7m/X5EXN3rQSnhr4XtmYiYbnWINRi2eSVmHoRhm5dTfaAgwgcKWg/h72l7gDUatnklZh6EoZq39ff4AAZvPRzxAQwY4QMFET5QEOEDBRE+UNB/Aaq2uAYFz6nKAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x18bc7074320>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 可视化混淆矩阵\n",
    "cfm = confusion_matrix(y_test, y_predict)\n",
    "plt.matshow(cfm, cmap=plt.cm.gray)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.        , 0.        , 0.00735294, 0.        , 0.        ,\n",
       "        0.00657895, 0.        , 0.        , 0.        , 0.        ],\n",
       "       [0.        , 0.        , 0.00735294, 0.01342282, 0.        ,\n",
       "        0.        , 0.        , 0.02205882, 0.02857143, 0.06802721],\n",
       "       [0.        , 0.        , 0.        , 0.00671141, 0.        ,\n",
       "        0.        , 0.        , 0.        , 0.00714286, 0.        ],\n",
       "       [0.        , 0.        , 0.        , 0.        , 0.        ,\n",
       "        0.03289474, 0.        , 0.00735294, 0.03571429, 0.        ],\n",
       "       [0.01342282, 0.03496503, 0.        , 0.        , 0.        ,\n",
       "        0.        , 0.        , 0.02205882, 0.        , 0.00680272],\n",
       "       [0.00671141, 0.02097902, 0.00735294, 0.        , 0.        ,\n",
       "        0.        , 0.        , 0.        , 0.00714286, 0.        ],\n",
       "       [0.        , 0.01398601, 0.        , 0.        , 0.        ,\n",
       "        0.00657895, 0.        , 0.        , 0.01428571, 0.        ],\n",
       "       [0.        , 0.        , 0.        , 0.00671141, 0.        ,\n",
       "        0.        , 0.        , 0.        , 0.00714286, 0.01360544],\n",
       "       [0.00671141, 0.06293706, 0.01470588, 0.02013423, 0.01333333,\n",
       "        0.02631579, 0.        , 0.        , 0.        , 0.02721088],\n",
       "       [0.        , 0.00699301, 0.        , 0.03355705, 0.        ,\n",
       "        0.01973684, 0.        , 0.01470588, 0.01428571, 0.        ]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 我们想找到我们预测错误的地方是哪些\n",
    "row_sums = np.sum(cfm, axis=1) # 每行求和\n",
    "err_matrix = cfm/row_sums  # 算出每个元素占一行和的比例\n",
    "np.fill_diagonal(err_matrix, 0) # 对角线上正确的预测用0填充,剩下的就是我们犯错的\n",
    "err_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAECCAYAAADesWqHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAACwNJREFUeJzt3U+IXeUZx/HfL5kJmrGiMNXMTKRRKKYilglj/RNwYVy0TVAkXVhQqJtsUo0iiEZUENyJKFiEIakbgy6SLIoUa0FddBOaTIQYx4KoiZk/mCyqks3MOE8X9wYSk845I/e9Z67P9wOBzOTk5WGY75xz75z7XkeEAOSyqukBAHQf4QMJET6QEOEDCRE+kBDhAwk1Fr7t39r+j+3PbD/V1Bx12b7O9ge2J20ft72r6ZnqsL3a9lHb7zQ9Sx22r7K93/an7a/1HU3PVMX24+3viY9tv2X7sqZnqtJI+LZXS/qLpN9JuknSH23f1MQsy7Ag6YmI+JWk2yXt7IGZJWmXpMmmh1iGVyW9GxEbJf1aK3x22yOSHpU0FhE3S1ot6YFmp6rW1Bn/N5I+i4jPI2JO0tuS7mtolloiYiYiJtp//06tb8iRZqdamu31krZK2tP0LHXYvlLSXZL2SlJEzEXEf5udqpY+SZfb7pO0VtJ0w/NUair8EUlfnffxKa3wiM5ne4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anN75AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x18bc8f0d978>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 可视化一下\n",
    "plt.matshow(err_matrix, cmap=plt.cm.gray)\n",
    "plt.show()\n",
    "# 可以看到真值是 8和1 预测错误的比较多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
